package com.yandype.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yandype.convert.TestUserConvert;
import com.yandype.entity.SybaseTestUser;
import com.yandype.entity.TestUser;
import com.yandype.mapper.SybaseTestUserMapper;
import com.yandype.mapper.TestUserAdbMapper;
import com.yandype.mapper.TestUserBdbMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class TestUserService extends ServiceImpl<TestUserAdbMapper, TestUser> {

    @Autowired
    private TestUserBdbMapper testUserBdbMapper;
    @Autowired
    SybaseTestUserMapper sybaseTestUserMapper;

    /**
     * 同步mysql b数据库数据到 mysql a数据库
     */
    public void syncBdbData2Adb(){
        List<TestUser> bdbUsers = testUserBdbMapper.selectList(null);
        log.info("查询Bdb 3383 数据库，\n users={}",bdbUsers);
        boolean adbBool = this.saveOrUpdateBatch(bdbUsers);
        log.info("同步Bdb 数据 到Adb 3382 数据库，\n 同步结果={}",adbBool);
    }

    /**
     * 同步sybase 数据库数据到 mysql a数据库
     */
    public void syncSybaseDbData2Adb(){
        List<SybaseTestUser> sybaseDbUsers = sybaseTestUserMapper.selectList(null);
        log.info("查询sybase 数据库，\n sybaseDbUsers={}",sybaseDbUsers);
        // 数据对象转换
        List<TestUser> testUsers = TestUserConvert.INSTANCES.sybaseTestUsers2TestUsers(sybaseDbUsers);
        log.info("将sybase 数据库数据转换mysql数据库对象模型，\n 转换结果={}",testUsers);
        boolean adbBool = this.saveOrUpdateBatch(testUsers);
        log.info("同步sybase 数据库数据 到Adb 3382 数据库，\n 同步结果={}",adbBool);
    }
}
